package com.zhilei.mq;

import com.zhilei.service.ResumeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author 简历消息的消费者
 */
@Component
@Slf4j
public class InitResumeMQConsumer {

    @Autowired
    private ResumeService resumeService;

    @RabbitListener(queues = {InitResumeMQConfig.INIT_RESUME_QUEUE})
    public void initResumeMQ(String payload, Message message) {

        log.info("Receive message from RabbitMQ: {}", message);
        log.info("Receive payload from payload: {}", payload);

        // TODO 处理简历消息，如入库等操作...
        String receivedRoutingKey = message.getMessageProperties().getReceivedRoutingKey();
        String routingKeyInitResume = InitResumeMQConfig.ROUTING_KEY_INIT_RESUME;

        if (routingKeyInitResume.equalsIgnoreCase(receivedRoutingKey)) {
            String userId = payload;
            resumeService.initResume(userId);
        }
    }
}
